/**
 * Created by lenovo on 2018/7/18.
 */
(function($){
    $('a').click(function(){
        var href = $(this).attr('href');
        var ajax = $(this).attr('b-href');
        //console.log(ajax);
        if(ajax){
            var loadingObj = (new $.zui.ModalTrigger({showHeader: false}));
            loadingObj.show();
//                var html = $.ajax({
//                    url: href,
//                    async:false
//                }).responseText;
//                $('.content-body').html(html);
            $('.content-body').load(href, function (response,status,xhr) {
                //"success", "notmodified", "error", "timeout" 或 "parsererror"
                if (status == "success" && xhr.status == 200 && xhr.readyState == 4) {//成功响应:返回有内容
                    loadingObj.close();
                } else if (status == "notmodified" && xhr.status == 200 && xhr.readyState == 4) {//成功响应:未修改
                    loadingObj.close();
                } else if (status == "error" && xhr.status == 404 && xhr.readyState == 4) {// 响应错误
                    // console.log(response);
                    // console.log(status);
                    // console.log(xhr);
                    new $.zui.Messager('404:找不到该页面', {
                        icon: 'bell', // 定义消息图标
                        type: 'warning'
                    }).show();
                    loadingObj.close();
                } else if (status == "timeout" && xhr.status == 200 && xhr.readyState == 4) {// 响应超时
                    console.log(response);
                    console.log(status);
                    console.log(xhr);
                    loadingObj.close();
                } else if (status == "parsererror" && xhr.status == 200 && xhr.readyState == 4) {// 分析器错误
                    console.log(response);
                    console.log(status);
                    console.log(xhr);
                    loadingObj.close();
                } else { // 未知
                    console.log(response);
                    console.log(status);
                    console.log(xhr);
                    loadingObj.close();
                }
            });
            return false;// 阻止a标签点击
        }else{
            console.log('直接执行');
        }
    });
    var BHref = function () {
    };
    BHref.prototype.aclick = function (url) {
        if(!url){
            if(console.error){
                console.error('URL is null');
            }
            throw new ReferenceError('URL is null');
            return false;
        }
        $('#common-tools-tag-a').attr('href', url).click();
    }
    $.fn.hrefClick = function (url, time) {
        if(!url){
            if(console.error){
                console.error('URL is null');
            }
            throw new ReferenceError('URL is null');
            return false;
        }
        if(!time){
            time = 10;
        }
        setTimeout(function () {
            $('#common-tools-tag-a').attr('href', url).click();
        }, time);

    }
})(jQuery);
